package com.ai.ly.goodsautocat.isphone;

import com.ai.ly.goodsautocat.vo.Fscore;

public class FscoreBuilder {
    
    public static Fscore buildFscore(double[] actualY,double[] predictY) {
        if (actualY.length!=predictY.length) {
            return null;
        }
        
        /**实际是true，预测也是true 的数量*/
        int truePositive=0;
        /**实际是false，预测是true 的数量*/
        int falsePositive=0;
        
        /**实际是true，预测是false 的数量*/
        int falseNegative=0;
        /**实际是false，预测也是false 的数量*/
        int trueNegative=0;
        
        int length=actualY.length;
        for (int i = 0; i < length; i++) {
            double aY=actualY[i];
            double pY=predictY[i];
            
            if (isTrue(aY)&&isTrue(pY)) {
                truePositive++;   
            }else if (isFalse(aY)&&isTrue(pY)) {
                falsePositive++;
            }else if (isTrue(aY)&&isFalse(pY)) {
                falseNegative++;
            }else if (isFalse(aY)&&isFalse(pY)) {
                trueNegative++;
            }
        }
        
        Fscore fscore=new Fscore(truePositive, falsePositive, falseNegative, trueNegative);
        return fscore;
    }
    
    public static boolean isTrue(double value) {
        return value>0;
    }
    public static boolean isFalse(double value) {
        return !isTrue(value);
    }
}
